<?php

require_once "class.db.php";

class kieudang extends db {

    function Kieu_Them(&$loi) {

        $thanhcong = true;

        $kieu = $this->processData($_POST['kieu']);
        $loai_id = (int) $_POST['loai_id'];

        if ($thanhcong == false) {
            return $thanhcong;
        } else {
            $sql = "INSERT INTO kieu VALUES(NULL,'$kieu',$loai_id)";
            mysql_query($sql) or die(mysql_error() . $sql);
        }
        return $thanhcong;
    }

    function Kieu_Edit($kieu_id, &$loi) {               

        $thanhcong = true;

        $kieu = $this->processData($_POST['kieu']);
        $loai_id = (int) $_POST['loai_id'];

        if ($thanhcong == false) {
            return $thanhcong;
        } else {
            $sql = "UPDATE kieu SET kieu = '$kieu',loai_id = $loai_id
					WHERE kieu_id = $kieu_id";
            mysql_query($sql) or die(mysql_error() . $sql);
        }
        return $thanhcong;
    }

    function getListKieuDang() {
        $sql = "SELECT * FROM kieu ORDER BY kieu_id ASC  ";
        $rs = mysql_query($sql) or die(mysql_error());
        return $rs;
    }
    
    function listkieudang_byloai($loai_id){
        $sql = "SELECT * FROM kieu WHERE loai_id = $loai_id ORDER BY kieu_id ASC  ";
        $rs = mysql_query($sql) or die(mysql_error());
        return $rs;
    }

    function Kieu_ChiTiet($kieu_id) {
        $sql = "SELECT * FROM kieu WHERE kieu_id = $kieu_id";
        $rs = mysql_query($sql) or die(mysql_error());
        return $rs;
    }

    function Khoanggia_Them(&$loi) {

        $thanhcong = true;

        $giatu = (int) $this->processData($_POST['giatu']);
        $giaden = (int) $this->processData($_POST['giaden']);
        $thutu = $this->KhoangGia_Thutumax();
        if ($thanhcong == false) {
            return $thanhcong;
        } else {
            $sql = "INSERT INTO khoanggia
					VALUES(NULL,'$giatu','$giaden',$thutu)";
            mysql_query($sql) or die(mysql_error() . $sql);
        }
        return $thanhcong;
    }
    function Khoanggia_Edit($kg_id) {        

        $giatu = (int) $this->processData($_POST['giatu']);
        $giaden = (int) $this->processData($_POST['giaden']);
       
        $sql = "UPDATE khoanggia SET giatu = '$giatu',giaden = '$giaden' WHERE kg_id = $kg_id";
        mysql_query($sql) or die(mysql_error() . $sql);

    }
    
    function KhoangGia_Thutumax(){
        $sql = "SELECT MAX(thutu) as thutumax FROM khoanggia";
        $rs = mysql_query($sql) or die(mysql_error());
        $row = mysql_fetch_assoc($rs);
        $thutumax = (int) $row['thutumax'];
        return ($thutumax+1);
    }
    function getListKhoangGia() {
        $sql = "SELECT * FROM khoanggia ORDER BY thutu ASC  ";
        $rs = mysql_query($sql) or die(mysql_error());
        return $rs;
    }
    function Khoanggia_ChiTiet($kg_id) {
        $sql = "SELECT * FROM khoanggia WHERE kg_id = $kg_id";
        $rs = mysql_query($sql) or die(mysql_error());
        return $rs;
    }   
}

?>